package com.yellowpage.ndc.service;

import java.util.List;
import java.util.Map;

import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

import com.yellowpage.white.common.Constants;
import com.yellowpage.white.common.PageRender;
import com.yellowpage.white.dao.QueryAssistantSQL;
import com.yellowpage.white.service.BaseServiceImpl;

import com.yellowpage.ndc.data.ProdGroupHis;
import com.yellowpage.ndc.dao.ProdGroupHisDao;

public class ProdGroupHisServiceImpl extends BaseServiceImpl implements ProdGroupHisService {
	  private ProdGroupHisDao prodGroupHisDao;
	
	  public void setProdGroupHisDao(ProdGroupHisDao prodGroupHisDao) {
		  this.prodGroupHisDao = prodGroupHisDao;
	  }
	
	
	  /* Smooth generate Method */ 
	  public ProdGroupHis getProdGroupHis(Long id){
	      return prodGroupHisDao.get(id);
	  }
	  
    public List<ProdGroupHis> getAllProdGroupHis(){
        return prodGroupHisDao.getAll();
    }
    
    public List<Map> queryProdGroupHisByPage(Map queryMap, PageRender pageRender) {		
        
		QueryAssistantSQL sqlAssistant = baseDao.newQueryAssistantSQL(
				"SELECT a.GROUP_ID,c.NAME as CREATE_USER_CODE,c.DISPLAY_NAME as LOGIN_NAME,a.CREATE_USER , a.CREATE_TIME , a.NOTE , a.ID ,"
				+ "case a.TYPE when 0 then '新增' when 1 then '修改' else '删除' end AS TYPE, a.CONTENT,b.NAME1, b.GROUP_ID as PROD_GROUP_ID "
				+ "FROM NDC_PROD_GROUP_HIS AS a LEFT JOIN CA_USER AS c ON (c.USER_ID = a.CREATE_USER) "
				+ "LEFT JOIN db_ndc.PROD_GROUP AS b ON (b.ID = a.GROUP_ID) where 1=1")
				    			.addCondition(" and a.GROUP_ID LIKE :groupId ")
				    			.addCondition(" and b.GROUP_ID LIKE :prodgroupId ")
				    			.addCondition(" and b.NAME1 LIKE :name1 ")
							    .addCondition(" and c.NAME LIKE :createUser ")
							    .addCondition(" and c.DISPLAY_NAME LIKE :loginName ")
							    .addCondition(" and a.CREATE_TIME >= :createTime ")
					    		.addCondition(" and a.CREATE_TIME <= :createTime_end ")
		    				    .addCondition(" and a.NOTE LIKE :note ")
							    .addCondition(" and a.ID LIKE :id ")
							    .addCondition(" and a.TYPE LIKE :type ")
							    .addCondition(" and a.CONTENT LIKE :content ")
							    ; 		    
		    

		List<Map> resultList = sqlAssistant.queryByPage(
				baseDao.getConnection(), queryMap, pageRender);

		return resultList;
	}
    
    
    public void saveProdGroupHis(ProdGroupHis prodGroupHis){
        prodGroupHisDao.save(prodGroupHis);
    }
    
	  public void updateProdGroupHis(ProdGroupHis prodGroupHis){
	      prodGroupHisDao.update(prodGroupHis);
	  }
	  
	  public void delete(List deleteList){
	      prodGroupHisDao.remove(deleteList);
	  }
	  
	  
	 
	
}	